/*
 * Copyleft 2012 Power by tangjiannan
 *
 * Project: app-crm
 * Date: Apr 4, 2012
 */
package com.crm.business.web.svcpkg.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.crm.business.web.svcpkg.service.SvcItemService;
import com.crm.common.web.service.impl.WebCommonServiceImpl;

/**
 * item Service implementations
 * 
 * @author tangjiannan
 * 
 */
public class SvcItemServiceImpl extends WebCommonServiceImpl implements
        SvcItemService {

    /** Logger */
    private static final Logger LOG = Logger
            .getLogger(SvcItemServiceImpl.class);

    @Override
    public boolean addItem(Map<String, Object> params) {
        int num = getCommonDao()
                .namingUpdate("sql_svc_item_addSvcItem", params);
        return num > 0 ? true : false;
    }

    @Override
    public void doQuery(Map<String, Object> params) {
        // query
        List<Map<String, Object>> list = getCommonDao().namingQueryForList(
                "sql_svc_item_querySvcItemByCond", params);

        LOG.info(list.size() + " items(s) fetched!");
        for (Map<String, Object> item : list) {
            item.put("status_disp_nm", getCdNmByValue("CD0006", item
                    .get("status")));
        }
        params.put("totalCount", list.size());
        params.put("svcitems", list);
    }

    /**
     * query a item model
     * 
     * @param params params
     */
    public void doQueryModel(Map<String, Object> params) {
        // query
        List<Map<String, Object>> list = getCommonDao().namingQueryForList(
                "sql_svc_item_querySvcItemByCond", params);
        if (!list.isEmpty()) {
            params.put("svcitem", list.get(0));
        }
    }

    /**
     * delete svcitem by id
     * 
     * @param params params
     * @return boolean
     */
    public boolean doDelItem(Map<String, Object> params) {
        int num = 0;
        num = getCommonDao().namingUpdate("sql_svc_item_deleteSvcItemByCond",
                params);
        return num > 0 ? true : false;
    }

    /**
     * update svcitem
     * 
     * @param params params
     * @return boolean
     */
    public boolean doUpdateItem(Map<String, Object> params) {
        int num = getCommonDao().namingUpdate("sql_svc_item_updateSvcitem",
                params);
        return num > 0 ? true : false;
    }

    /** impl for common start */
    @Override
    public List<Map<String, Object>> querySvcItems(Map<String, Object> args) {
        // query
        List<Map<String, Object>> list = getCommonDao().namingQueryForList(
                "sql_svc_item_querySvcItemByCond", args);
        return list;
    }

}
